Hello all:
Before I pose my query, I will say I have seen several words of caution on not using globals unless absolutely necessary. My objective below is to develop a program that takes in argument for a directory name and sets the working directory to my project at hand with globals pointing to subdirectories or other directories proximal/higher up relative to the root project directory. I want to use -include- do files from different directories a different discontinuous chunks of the project master do file (where I presume locals would not work, other than if I repetitively declare them within the chunk scope).
Is this structure below really unstable? I am planning to have all future projects use the same subdirectory names otherwise. I was planning to convert the one below into a program that I could readily call for each project I would work on. Do any of you foresee major issues? Again, I have 3 different PCs and my student has a MAC and we work off Dropbox. I am fairly certain that I would not use the global names in any local macro names, but would like to know what could go wrong. If there is an easier stable way without globals, I am happy to take pointers.
Sample call in master do.file:
Before I pose my query, I will say I have seen several words of caution on not using globals unless absolutely necessary. My objective below is to develop a program that takes in argument for a directory name and sets the working directory to my project at hand with globals pointing to subdirectories or other directories proximal/higher up relative to the root project directory. I want to use -include- do files from different directories a different discontinuous chunks of the project master do file (where I presume locals would not work, other than if I repetitively declare them within the chunk scope).
Is this structure below really unstable? I am planning to have all future projects use the same subdirectory names otherwise. I was planning to convert the one below into a program that I could readily call for each project I would work on. Do any of you foresee major issues? Again, I have 3 different PCs and my student has a MAC and we work off Dropbox. I am fairly certain that I would not use the global names in any local macro names, but would like to know what could go wrong. If there is an easier stable way without globals, I am happy to take pointers.
Code:
*! Program dropbox destinations 1.0 * Sets Dropbox for all 3 PC and MACs * Define working directory for Project folder * Argument to set project folder as working dir *----------------------------------- cap program drop stemmer program define stemmer *Stata versions version 17 clear all set linesize 80 set more off frames reset cap drop __000* cls args prfolder // Define all 4 roots directories to dropbox across Emily and GV PCs *------------------------------------------------------------------- cap cd "/Users/emilys/Dropbox/" cap cd "C:/Users/Vijayalakshmi/Dropbox/" cap cd "C:/Users/NewPC/Dropbox/" cap cd "D:/gvenkataraman/Documents/Dropbox/" *-------------DEFINE STEM DIR---------------------------* local stem `c(pwd)' // Everything leading upto Dropbox dir di "`stem'" *---------DEFINE WORKING & SAVING DIR-------------------* if regexm(c(os), "Mac") == 1 { global working "`stem'//gv_includes/" global prfolder "`stem'//`prfolder'/" global output "${prfolder}//outputs" global prdofile "${prfolder}//dofiles" } else if regexm(c(os), "Windows") == 1 { global working "`stem'//Girish Files/gv_includes/" global prfolder "`stem'//Girish Files/A_UOC academic/`prfolder'" global output "${prfolder}//outputs" global prdofile "${prfolder}//dofiles" } *------------CHANGE WORKING DIR to Project ROOT----------* cd "${working}" di "Working directory (working) : $working" di "Project dir (prfolder) : $prfolder" di "Output dir (outputs) : $output" di "Project do file dir (prdofile) : $prdofile" cd "$prfolder" end
Code:
stemmer "Prj_akp53" use "$prfolder//p53merged-v2.dta" qui include "./p53select.doh" ***Several lines down further sts graph.... graph export "${output}//testgraph.png", replace
Comment